import {App, message as antdMessage, Modal as antdModal, notification as antdNotification,} from "antd";

import type {MessageInstance} from "antd/es/message/interface";
import type {NotificationInstance} from "antd/es/notification/interface";
import type {ModalStaticFunctions} from "antd/es/modal/confirm";

let message: MessageInstance = antdMessage;
let notification: NotificationInstance = antdNotification;

// because warn is deprecated, so we need to remove it.
const {warn, ...resetFns} = antdModal;
let modal: Omit<ModalStaticFunctions, "warn"> = resetFns;

/**
 * This component is used to escape the antd's static functions.
 * 详见：
 * 1. https://ant.design/components/app-cn
 * 2. https://ant.design/docs/react/customize-theme-cn#%E4%BF%AE%E6%94%B9%E7%BB%84%E4%BB%B6%E5%8F%98%E9%87%8F-component-token 下方注意
 */
function EscapeAntd() {
    const staticFunctions = App.useApp();

    message = staticFunctions.message;
    notification = staticFunctions.notification;
    modal = staticFunctions.modal;

    return null;
}

export {
    message,
    notification,
    modal,
}

export default EscapeAntd;